package w83b.w83bOperacionesPaso.w83bActas;


import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import w83b.w83bBeans.W83bActasBean;
import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

// TODO: Auto-generated Javadoc
/**
 * The Class W83bTablaAgrupacionesOP.java.
 *
 * @author Deusto Sistemas
 */
public class W83bTablaImpugnacionOPAction extends Q70ActionPasoOP{

	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//Guardamos la accion en el contexto	
		
		String seleccionados = (String)request.getParameter("seleccionados");
		String[] seleccionado = seleccionados.split("_");
		List listaActas = (ArrayList)contexto.get("w83bListaActas");
		W83bActasBean actaSeleccionada = new W83bActasBean();
		if(4<seleccionado.length){
			actaSeleccionada = (W83bActasBean)listaActas.get(Integer.parseInt(seleccionado[4]));
			
			if(null!=actaSeleccionada&&StringUtils.isNotEmpty(actaSeleccionada.getNumActa())&&actaSeleccionada.getNumActa().split("/").length<2){
				W83bActasBean actaTemp = actaSeleccionada;
				actaSeleccionada = new W83bActasBean();
				
				actaSeleccionada.setNumActa(actaTemp.getNumActaTerritorio()+"/"+actaTemp.getNumActaAno()+"/"+actaTemp.getNumActa());
				actaSeleccionada.setCodTerritorioActa(actaTemp.getNumActaTerritorio());
				actaSeleccionada.setVersion(actaTemp.getVersion());
			}
		}else{
			W83bActasBean acta =  (W83bActasBean)contexto.get("w83bNuevaActaBean");
			
			actaSeleccionada.setNumActa(acta.getNumActaTerritorio()+"/"+acta.getNumActaAno()+"/"+acta.getNumActa());
			actaSeleccionada.setCodTerritorioActa(acta.getNumActaTerritorio());
			actaSeleccionada.setVersion(acta.getVersion());
			
		}
		
		contexto.set("w83bActasBean",actaSeleccionada);
		
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		return mapping.findForward("ok");
	}

}
